package com.kuaihuoyun.ctms.api;

import com.kuaihuoyun.ctms.dto.CargoAddRequest;
import com.kuaihuoyun.ctms.dto.CargoUpdateRequest;
import com.kuaihuoyun.ctms.dto.CtmsResponse;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.POST;
import retrofit2.http.Query;

import java.io.IOException;

/**
 * Created by kevin on 2018/1/5.
 */
public class CargoService extends BaseService {
    public CargoService(String url, String token) {
        super(url, token);
    }

    public CtmsResponse addOrderCargo(CargoAddRequest cargoAddRequest) throws IOException {
        Call<CtmsResponse> responseCall =
                retrofit.create(CargoService.CargoApi.class).addOrderCargo(token,cargoAddRequest);
        final Response<CtmsResponse> response = responseCall.execute();
        if(!response.isSuccessful()) {
            return CtmsResponse.create(response);
        }
        return response.body();
    }

    public CtmsResponse removeOrderCargo(String cargoNumber) throws IOException {
        Call<CtmsResponse> responseCall =
                retrofit.create(CargoService.CargoApi.class).removeOrderCargo(token,cargoNumber);
        final Response<CtmsResponse> response = responseCall.execute();
        if(!response.isSuccessful()) {
            return CtmsResponse.create(response);
        }
        return response.body();
    }   public CtmsResponse modifyOrderCargo(CargoUpdateRequest cargoUpdateRequest) throws IOException {
        Call<CtmsResponse> responseCall =
                retrofit.create(CargoService.CargoApi.class).modifyOrderCargo(token,cargoUpdateRequest);
        final Response<CtmsResponse> response = responseCall.execute();
        if(!response.isSuccessful()) {
            return CtmsResponse.create(response);
        }
        return response.body();
    }

    interface CargoApi {
        @POST("/cargo/add")
        Call<CtmsResponse> addOrderCargo(@Query("access_token") String token, @Body CargoAddRequest request) throws IOException;

        @POST("/cargo/remove")
        Call<CtmsResponse> removeOrderCargo(@Query("access_token") String token, @Body String cargoNumber) throws IOException;

        @POST("/cargo/update")
        Call<CtmsResponse> modifyOrderCargo(@Query("access_token") String token, @Body CargoUpdateRequest request) throws IOException;
    }



}
